package com.feel.web.controller.oss;

import com.feel.common.annotation.Log;
import com.feel.common.core.controller.BaseController;
import com.feel.common.core.domain.AjaxResult;
import com.feel.common.core.page.TableDataInfo;
import com.feel.common.enums.BusinessType;
import com.feel.common.utils.poi.ExcelUtil;
import com.feel.system.domain.SysOss;
import com.feel.system.service.ISysOssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件上传Controller
 *
 * @author Noel
 * @date 2021-03-01
 */
@RestController
@RequestMapping("/system/sys_oss")
@Api(tags="文件上传接口",value = "文件上传接口")
public class SysOssController extends BaseController {
    @Autowired
    private ISysOssService sysOssService;

    /**
     * 查询文件上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:sys_oss:list')")
    @GetMapping("/list")
    @ApiOperation("查询文件上传列表")
    public TableDataInfo list(SysOss sysOss)
    {
        startPage();
        List<SysOss> list = sysOssService.selectSysOssList(sysOss);
        return getDataTable(list);
    }

    /**
     * 导出文件上传列表
     */
    @PreAuthorize("@ss.hasPermi('system:sys_oss:export')")
    @Log(title = "文件上传", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出文件上传列表")
    public AjaxResult export(SysOss sysOss)
    {
        List<SysOss> list = sysOssService.selectSysOssList(sysOss);
        ExcelUtil<SysOss> util = new ExcelUtil<SysOss>(SysOss.class);
        return util.exportExcel(list, "sys_oss");
    }

    /**
     * 获取文件上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sys_oss:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取文件上传详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysOssService.selectSysOssById(id));
    }

    /**
     * 新增文件上传
     */
    @PreAuthorize("@ss.hasPermi('system:sys_oss:add')")
    @Log(title = "文件上传", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增文件上传")
    public AjaxResult add(@RequestBody SysOss sysOss)
    {
        return toAjax(sysOssService.insertSysOss(sysOss));
    }

    /**
     * 修改文件上传
     */
    @PreAuthorize("@ss.hasPermi('system:sys_oss:edit')")
    @Log(title = "文件上传", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改文件上传")
    public AjaxResult edit(@RequestBody SysOss sysOss)
    {
        return toAjax(sysOssService.updateSysOss(sysOss));
    }

    /**
     * 删除文件上传
     */
    @PreAuthorize("@ss.hasPermi('system:sys_oss:remove')")
    @Log(title = "文件上传", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除文件上传")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysOssService.deleteSysOssByIds(ids));
    }
}
